/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package sonia.golf;

//~--- non-JDK imports --------------------------------------------------------

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import sonia.golf.dao.DAOFactory;
import sonia.golf.dao.GenericDAO;

/**
 *
 * @author Sebastian Sdorra
 */
public class CourseActivity extends AbstractDAOListActivity<Course, String>
{

  /**
   * Method description
   *
   *
   * @param name
   *
   * @return
   */
  @Override
  protected Course createNewItem(String name)
  {
    return new Course(name);
  }

  /**
   * Method description
   *
   *
   * @param savedInstanceState
   */
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    getListView().setOnItemClickListener(new OnItemClickListener()
    {
      public void onItemClick(AdapterView<?> av, View view, int i, long l)
      {
        Course course = itemList.get(i);

        showDetailActivity(course);
      }
    });
  }

  /**
   * Method description
   *
   *
   * @param item
   */
  @Override
  protected void postAdd(Course item)
  {
    showDetailActivity(item);
  }

  //~--- get methods ----------------------------------------------------------

  /**
   * Method description
   *
   *
   * @return
   */
  @Override
  protected GenericDAO<Course, String> getDAO()
  {
    return DAOFactory.getInstance().getCourseDAO();
  }

  /**
   * Method description
   *
   *
   * @return
   */
  @Override
  protected int getMenuId()
  {
    return R.layout.menucourse;
  }

  /**
   * Method description
   *
   *
   * @return
   */
  @Override
  protected int getNewItemMenuId()
  {
    return R.id.menu_new_course;
  }

  /**
   * Method description
   *
   *
   * @return
   */
  @Override
  protected int getNewItemMessageId()
  {
    return R.string.new_course;
  }

  /**
   * Method description
   *
   *
   * @param item
   *
   * @return
   */
  @Override
  protected String getRemoveMessage(Course item)
  {
    return getResources().getString(R.string.remove_course, item.getName());
  }

  //~--- methods --------------------------------------------------------------

  /**
   * Method description
   *
   *
   * @param course
   */
  private void showDetailActivity(Course course)
  {
    Intent intent = new Intent(this, CourseDetailActivity.class);

    intent.putExtra(StrokeCounter.PARAMETER_COURSE, course.getName());
    startActivity(intent);
  }
}
